package cn;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * @author Mxb
 * @version 1.0
 * @date 2020/10/12 18:56
 */
public class TestMap {
    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();

        map.put("1", "test1");
        map.put("2", "test2");
        map.put("3", "test3");
        map.put("4", "test4");
        map.put("5", "test5");

        //System.out.println("通过Map.keySet遍历key和value：");
        //for(String key:map.keySet()){
        //    System.out.println("key："+key);
        //    System.out.println("value："+map.get(key));
        //    System.out.println("======================");
        //}
        System.out.println("通过Map.entrySet使用iterator遍历key和value: ");
        Iterator iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, String> entry = (Map.Entry<String, String>) iterator.next();
            System.out.println("Key: " + entry.getKey());
            System.out.println("Value: " + entry.getValue());
            System.out.println("======================");
        }

        //System.out.println("通过Map.entrySet遍历key和value");
        //for (Map.Entry<String, String> entry : map.entrySet()) {
        //    System.out.println("Key: " + entry.getKey());
        //    System.out.println("Value: " + entry.getValue());
        //    System.out.println("======================");
        //}

        //System.out.println("通过Map.values()遍历所有的value，但不能遍历key");
        //for (String v : map.values()) {
        //    System.out.println("value：" + v);
        //}
    }
}
